package com.car.service;

import com.car.dao.CarDao;
import com.car.dao.EmployeeDao;
import com.car.dao.impl.CarDaoImpl;
import com.car.dao.impl.EmployeeDaoImpl;
import com.car.domain.Car;
import com.car.domain.Employee;
import com.car.utils.NumberUtil;

import java.util.Scanner;

public class EmployeeService {
    private static final EmployeeDao employeeDao = new EmployeeDaoImpl();
    private static final CarDao cardao = new CarDaoImpl();
    //登录
    public Employee login(Scanner sc) throws Exception {
        System.out.println("员工登录");
        System.out.println("请输入工号：");
        String workId = sc.next();
        System.out.println("请输入密码：");
        String password = sc.next();
        Employee employee = employeeDao.findByWorkId(workId);
        if (employee == null || !"000000".equals(password)){
            return null;
        }
        return employee;
    }

    public void addCar(Employee employee, Scanner sc) throws Exception {
        System.out.println("上架汽车");
        Car car = new Car();

        System.out.println("请输入汽车名称：");
        String name = sc.next();
        car.setName(name);

        System.out.println("请输入汽车品牌：");
        String brand = sc.next();
        car.setBrand(brand);

        System.out.println("请输入汽车颜色：");
        String color = sc.next();
        car.setColor(color);

        System.out.println("请输入汽车类型：");
        String type = sc.next();
        car.setType(type);

        System.out.println("请输入汽车价格：");
        Double price = sc.nextDouble();
        car.setPrice(price);

        car.setCarNum(NumberUtil.generateCardNum());
        car.setEmployeeId(employee.getId());
        //新增到数据库
        int i = cardao.add(car);
        if (i>0){
            System.out.println("上架成功！");
        }else {
            System.out.println("操作失败！");
        }

    }
}